﻿using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using ProductionLine.API.Application.Command.Plan.Read;
using ProductionLine.API.Application.Command.Plan.Write;
using ProductionLine.API.Application.Command.PlanDetail.Read;
using ProductionLine.Domain.Material;
using ProductionLine.Domain.Plan;
using ProductionLine.Domain.Product;
using ProductionLine.ErrorCode;
using ProductionLine.Extensions;
using Sale.Domain;

namespace ProductionLine.API.Controllers
{
    /// <summary>
    /// 生产计划
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    [Authorize]
    public class PlanController : ControllerBase
    {
        IMediator mediator;
        ILogger<PlanController> logger;

        public PlanController(IMediator mediator, ILogger<PlanController> logger)
        {
            this.mediator = mediator;
            this.logger = logger;
        }
        /// <summary>
        /// 生产计划查询
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIPaging<List<PlanDTO>>> GetPlan([FromQuery]GetPlanCommand request)
        {
            logger.LogInformation("查询生产计划成功");
            return mediator.Send(request);
        }
        /// <summary>
        /// 生产计划添加
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<APIResult<int>> AddPlan(AddPlanCommand request)
        {
            logger.LogInformation("新增生产计划成功");
            return await mediator.Send(request);
        }
        /// <summary>
        /// 生产计划编辑
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public Task<APIResult<int>> UpdatePlan(UpdatePlanCommand request)
        {
            logger.LogInformation("编辑生产计划成功");
            return mediator.Send(request);
        }
        /// <summary>
        /// 生产计划删除
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public Task<APIResult<int>> DelPlan(DelPlanCommand request)
        {
            logger.LogInformation("删除生产计划成功");
            return mediator.Send(request);
        }
        /// <summary>
        /// 计划详情基础信息
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIResult<PlanModel>> GetPlanOne([FromQuery]GetOnePlanCommand request)
        {
            logger.LogInformation("查询生产计划详情成功");
            return mediator.Send(request);
        }
        /// <summary>
        /// 物料明细
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIResult<List<MaterialDetailIModel>>> GetMateriaDetail([FromQuery]GetMaterialDetailCommand request)
        {
            logger.LogInformation("查询物料成功");
            return mediator.Send(request);
        }
       
        /// <summary>
        /// 产品
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIResult<List<ProductModel>>> GetProduct([FromQuery]GetProductCommand request)
        {
            logger.LogInformation("查询产品成功");
            return mediator.Send(request);
        }
        /// <summary>
        /// 产品详情
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIResult<ProductTrueDTO>> GetProductTrue([FromQuery]GetProductTrueCommand request)
        {
            logger.LogInformation("查询产品详情成功");
            return mediator.Send(request);
        }
    }
}
